{% extends "course/nav.html" %}
{% block title %}HomePage{% endblock %}
{% block content %}
    {% load static %}
    <link href="{% static 'css/list.css' %}" rel="stylesheet">
    <div class="main-container">
        <div class="main-bar">
            <form class="search-form" method="post">
                {% csrf_token %}
                <input class="input" id="search-key" type="text" name="search" {% if search_key != None %}value="{{ search_key }}" {% endif %}/>
                <input class="button" type="submit" value="搜索课程" />
            </form>

            <input class="button right-button" type="button" value="创建课程"  onclick='window.open("{% url 'create_course' %}")' />
        </div>
        <table class="item-list course-list">
            <thead>
                <tr>
                    <th class="course-no">课程编号</th>
                    <th class="course-name">名称</th>
                    <th class="course-credit">学分</th>
                    <th class="course-number">当前人数<br>/总人数</th>
                    <th class="course-year">年份</th>
                    <th class="course-semester">学期</th>
                    <th class="course-status">状态</th>
                    <th class="course-operation">操作</th>
                </tr>
            </thead>
            <tbody>
                {% for course in course_list %}
                    <tr id="course-id-{{ course.id }}">
                    <td class="course-no">{{ course.id }}</td>
                    <td class="course-name">{{ course.name }}</td>
                    <td class="course-credit">{{ course.credit }}</td>
                    <td class="course-number">{{ course.get_current_count }}/{{ course.max_number }}</td>
                    <td class="course-year">{{ course.year }}</td>
                    <td class="course-semester">{{ course.get_semester_display }}</td>
                    <td class="course-status">{{ course.get_status_text }}</td>
                    <td class="course-operation">
                        {% if course.status < 4 %}
                            <input class="button right-button" type="button" value="{{ course.get_op_text }}"
                              onclick='location.href="{% url 'handle_course' course.id course.status %}"' />
                        {% endif %}
                        {% if course.status == 4 %}
                        {# 结课后给分 #}
                            <input class="button right-button" type="button" value="{{ course.get_op_text }}"
                                   onclick='location.href="{% url 'view_detail' course.id %}"' />
                        {% else %}
                            <input class="button right-button" type="button" value="查看详情"
                                   onclick='location.href="{% url 'view_detail' course.id %}"' />
                        {% endif %}
                    </td>
                    </tr>
                {% endfor %}
            </tbody>

        </table>
    </div>
{% endblock %}